package com.orangelife.mobile.lookRepair.adapter;

import java.util.List;
import java.util.Map;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.curry.orangelife.mobile.R;
import com.curry.android.adapter.FatherAdapter;

public class PricingAndValuationListAdapter<T> extends FatherAdapter<T> {

	private Context context;
	private List<Map<String,Object>> list;
	private Map<String,Object> infomap;
	@SuppressWarnings("unused")
	private LayoutInflater inflater;
	private ViewHolder holder;
	
	public PricingAndValuationListAdapter(Context context,List<Map<String,Object>> list) {
		this.context = context;
		this.list = list;
		inflater = (LayoutInflater) context
				.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
	}

	@Override
	public int getCount() {
		if (list != null) {
			return list.size();
		} else {
			return 0;
		}
	}

	@Override
	public Object getItem(int position) {
		if (list != null) {
			return list.get(position);
		} else {
			return null;
		}
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	@SuppressWarnings("unchecked")
	@Override
	public View getView(int posiiton, View convertView, ViewGroup parent) {
		if(convertView == null){
			holder = new ViewHolder();
			convertView = LayoutInflater.from(context).inflate(R.layout.item_lv_pricing_and_valuation, null);
			holder.tvMasterType = (TextView)convertView.findViewById(R.id.tvMasterType);
			holder.tvWorkTime = (TextView)convertView.findViewById(R.id.tvWorkTime);
			holder.tvPrice = (TextView)convertView.findViewById(R.id.tvPrice);
			convertView.setTag(holder);
		}else{
			holder = (ViewHolder) convertView.getTag();
		}
		infomap = list.get(posiiton);
		int number = Integer.parseInt(infomap.get("number").toString());
		float cost = Float.parseFloat(infomap.get("workCost").toString());
		float days = Float.parseFloat(infomap.get("days").toString());
		holder.tvMasterType.setText(infomap.get("wokertypeName")+"/每天"+cost);
		holder.tvWorkTime.setText(days+"天");
		float total = number * cost * days;
		holder.tvPrice.setText("= ¥"+total);
		return convertView;
	}
	
	class ViewHolder{
		/** 师傅类型  */
		private TextView tvMasterType;
		/**工作时间*/
		private TextView tvWorkTime;
		/** 价格*/
		private TextView tvPrice;
	}
	@SuppressWarnings("unchecked")
	@Override
	public BaseAdapter setList(List<T> list) {
		this.list = (List<Map<String, Object>>) list;
		return PricingAndValuationListAdapter.this;
	}

}
